package com.superm.utils;

import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;
import java.util.Random;

public class Tool implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * 将一个字符串拆分成字符,加成逗号,返回
	 * @param str
	 * @return
	 */
	public static String joinString(Object str){
		StringBuilder strYi = new StringBuilder(); 
		String[] strArray =str.toString().split("-");	
		for (int i = 0; i < strArray.length; i++) {	
		strYi.append(strArray[i]+",");
		}
		//最后的逗号截取和第一个
		strYi.deleteCharAt(strYi.length()-1);
		return strYi.toString();
	}
	
	
	/**
	 * 生成一个随机数
	 * @return
	 */
	public static int random(){
		Random random = new Random();
		return random.nextInt(999999);
	}
	/**
	 * 日期随机数
	 * @return
	 */
	public static String dateRandom(String bianhao){
		Long num = (long)(Math.random()*(999999999999l - 100000000000l) + 100000000000l);
		return bianhao+getDate()+""+num;
	}
	
	
	/**
	 * 获取年月日随机数
	 * @return
	 */
	public static String getDate(){
		StringBuffer dataStr = new StringBuffer();
		Calendar cal = Calendar.getInstance();
		  dataStr.append(cal.get(Calendar.YEAR)).delete(1,3);//获取年份
		  dataStr.append(cal.get(Calendar.MONTH)+1);//获取月份
		  dataStr.append(cal.get(Calendar.DATE));//获取日
		  return dataStr.toString();
	}

}
